package com.raysun.androidbase.interaction

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.raysun.androidbase.databinding.ActivityVisibilityBinding

class VisibilityActivity : AppCompatActivity() {

    private lateinit var binding: ActivityVisibilityBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = ActivityVisibilityBinding.inflate(layoutInflater)
        setContentView(binding.root)

        binding.checkWhetherBrowserAvailable.setOnClickListener {
            Intent(Intent.ACTION_VIEW).apply {
                data = Uri.parse("https://www.baidu.com")
            }.let {
                val resolveInfoList = packageManager.queryIntentActivities(it, 0)
                Log.d(
                    "Raysunshine",
                    "checkWhetherBrowserAvailable: ${resolveInfoList.isNotEmpty()}"
                )
                for (resolveInfo in resolveInfoList) {
                    resolveInfo.activityInfo.name.also { name ->
                        Log.d("Raysunshine", "onCreate: $name")
                    }
                }
            }
        }

        binding.getAllPackagesInfo.setOnClickListener {
            val installedPackages = packageManager.getInstalledPackages(0)
            for (ip in installedPackages) {
                Log.d("Raysunshine", "${ip.applicationInfo.loadLabel(packageManager)} ")
            }
        }
    }
}